package com.springboot.shiro.controller;

import com.springboot.shiro.pojo.User;
import com.springboot.shiro.service.UserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

/**
 * @Date: 2019/10/22 17:12
 * @author: ybzhu
 * @Description： 用户控制器
 */
@RestController
@RequestMapping("user")
@ResponseBody
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 系统管理
     * @return
     */
    @RequiresPermissions("sys:user")
    @RequestMapping(value = "/",method = RequestMethod.GET)
    public String index() {
        return "欢迎来到系统管理页面";
    }

    /**
     * 用户管理
     * @return
     */
    @RequiresPermissions("sys:user:list")
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public String list() {
        return "欢迎来到用户管理页面";
    }
    /**
     * 新增用户
     * @return
     */
    @RequiresPermissions("sys:user:add")
    @RequestMapping(value = "/add",method = RequestMethod.GET)
    public String add() {
        User user = new User();
        user.setId((UUID.randomUUID().toString().replace("-","")));
        user.setNickName("朱亚彬");
        user.setLoginName("yabzhu");
        user.setPassword("123456");
        userService.insert(user);
        return "创建用户成功";
    }

    /**
     * 编辑用户
     * @return
     */
    @RequiresPermissions("sys:user:edit")
    @RequestMapping(value = "/edit",method = RequestMethod.GET)
    public String edit() {
        return "编辑用户成功";
    }

    /**
     * 删除用户
     * @return
     */
    @RequiresPermissions("sys:user:delete")
    @RequestMapping(value = "/delete",method = RequestMethod.GET)
    public String delete() {
        userService.updateByUserName("ybzhu");
        return "删除用户成功";

    }

    /**
     * 用户锁定
     * @return
     */
    @RequiresPermissions("sys:user:lock")
    @RequestMapping(value = "/lock",method = RequestMethod.GET)
    public String lock() {
        return "用户锁定成功";
    }

}
